package mybag1;

    import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

    /**
     * @author
     * @date 2018/05/22/12:04
     * @description JAVA-XML
     */

    public class UserClient {

        public static void main(String[] args) {
            Socket socket = null;
            ObjectOutputStream writer = null;
            BufferedReader reader = null;
            try {
                socket = new Socket(InetAddress.getLocalHost(), 1234);
                reader = new BufferedReader(new InputStreamReader(System.in));
                System.out.print("请输入用户名：");
                String username = reader.readLine();
                System.out.print("请输入密码：");
                String password = reader.readLine();
                User user = new User(username, password);
                writer = new ObjectOutputStream(socket.getOutputStream());
                writer.writeObject(user);
                writer.flush();

                reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String content = reader.readLine();
                System.out.println(content);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (writer != null) {
                        writer.close();
                    }
                    if (reader != null) {
                        reader.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

